package com.snake.springboot.custom.service.impl.points;

import com.github.pagehelper.Page;
import com.snake.springboot.custom.api.model.points.PointsRgeTempModel;
import com.snake.springboot.custom.api.request.page.PageQuery;
import com.snake.springboot.custom.api.request.points.PointsRgeTempQuery;
import com.snake.springboot.custom.api.service.points.PointsRgeTempService;
import com.snake.springboot.custom.dao.mybatis.entity.points.PointsRgeTempDO;
import com.snake.springboot.custom.dao.mybatis.mappers.points.PointsRgeTempMapper;
import com.snake.springboot.custom.service.assemble.points.PointsRgeTempAssemble;
import com.snake.springboot.custom.service.utils.PageUtils;
import org.snake.common.result.ReturnList;
import org.snake.common.utils.ListUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PointsRgeTempServiceImpl implements PointsRgeTempService{

    @Autowired
    private PointsRgeTempMapper rgeTempMapper;

    @Override
    public PointsRgeTempModel addPointsRgeTemp(PointsRgeTempModel model) {
        PointsRgeTempDO tempDO = PointsRgeTempAssemble.rgeTempAssemble(model,true);
        rgeTempMapper.insert(tempDO);
        return model;
    }

    @Override
    public void modifyPointsRgeTemp(PointsRgeTempModel model) {
        PointsRgeTempDO tempDO = PointsRgeTempAssemble.rgeTempAssemble(model,false);
        rgeTempMapper.update(tempDO);
    }

    @Override
    public void removePointsRgeTemp(String id) {
        rgeTempMapper.delete(id);
    }

    @Override
    public ReturnList<PointsRgeTempModel> queryPointsRgeTempList(PageQuery<PointsRgeTempQuery> params) {
        Page<Object> objects = PageUtils.forcePage(params.getPage());
        PointsRgeTempDO queryDO = PointsRgeTempAssemble.rgeTempAssemble(params.getParams());
        List<PointsRgeTempDO> dos = rgeTempMapper.queryPointsRgeTempList(queryDO);
        List<PointsRgeTempModel> modelList = ListUtils.copy(dos, PointsRgeTempModel.class);
        return new ReturnList<>(modelList,objects.getTotal());
    }

    @Override
    public PointsRgeTempModel queryById(String tempId) {
        PointsRgeTempDO tempDO = rgeTempMapper.queryById(tempId);
        PointsRgeTempModel model = PointsRgeTempAssemble.rgeTempModelAssemble(tempDO);
        return model;
    }
}
